<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <style>
    .list{
    	background-color: #FFFFFF;
    }
    .list .item{
    	border-bottom: 1px solid #ebebeb;
    	padding: 0.7em 0.7em 0.8em 0.6em;
    }
    .list .itemActive{
    	background-color: #efefef;
    }
    .list .item .title{
    	color: #333333;
    	font-size: 1em;
    	line-height: 1.2em;
    	word-break: break-all; word-wrap:break-word;	/* 自动换行 */
    }
    .list .item .info{
    	font-size: 0.7em;
    	padding-top: 0.8em;
    }
    .list .item .info span{
    	color: #9a9a9a;
    	margin-right: 1em;
    }
    </style>
</head>
<body>
<div id="wrap">
	<div class="list" id="list">
		<!--div class="item"  tapmode="itemActive" onclick="openTopic()">
			<div class="title">
			原创精选————风骚美女，性感极品的女人No..49028[12P]
			</div>
			<div class="info">
				<span class="author">oschina</span><span class="time">4小时前</span><span class="commentCount">1评论</span>
			</div>
		</div-->
	</div>
	
</div>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script>
apiready = function () {


	$api.setStorage('nowPage', 1);
	$api.setStorage('totalPages', 0);
	getList(1, 'first');		// 首次加载
	
	// 下拉刷新
	api.setRefreshHeaderInfo({
	    visible: true,
	    loadingImg: 'widget://image/pulltorefresh_arrow.png',
	    bgColor: '#ccc',
	    textColor: '#fff',
	    textDown: '下拉刷新...',
	    textUp: '松开刷新...',
	    showTime: true
	}, function(ret, err){
	    //从服务器加载数据，完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
	    getList($api.getStorage('nowPage'), 'refresh');
	});
};

function getList(page, type){
	var pageParam = api.pageParam;
	var url = OpenAPI.forum_list + pageParam.fid + '&page=' + page;
	log(url);
	api.showProgress({
	    style: 'default',
	    animationType: 'fade',
	    modal: false
	});
	
	api.ajax({
	    url: url,
	    method: 'get',
	    timeout: 30,
	    dataType: 'text',
	    charset: 'gbk',
	    returnAll:false,
	},function(html,err){
	    if (html) {
        	html = htmlcompress(html);	// 压缩html
        	
        	if($api.getStorage('nowPage') == 1 || $api.getStorage('nowPage') == 0){
        		// 获取总页数
				var  mPage=html.match(/page=(\d+)\" style=\"font-weight:bold\">＞<\/a><\/div><\/td><td style=\"text-align:right\"><a href=\"post\.php/);
				if(null != mPage){
					$api.setStorage('totalPages', mPage[1]);
				}
        	}
        	// 提取所以帖子的相关信息
			var tid = '';
			var title = '';
			var author = '';
			var pubdate = '';
			var comment = '';
			var listhtml = '';
			html.replace(/class="tr3 t_one"(.*?)<\/td>	<\/tr>/g, function(a,b) {
				
			    var  mTids = b.match(/<h3><a href=".+(\/|=){1}(\d+)(\.html)?" target="_blank" id="">/);
				if(null != typeof mTids){
					tid = mTids[2];	// tid
					
					var  mTitle = b.match(/target="_blank" id="">(.+)<\/a><\/h3>/);
					title = mTitle[1];	// 标题
					
					var  mAuthor = b.match(/class="bl">(.+)<\/a>		<div class="f10">/);
					author = mAuthor[1];	// 作者
					
					var  mPubdate = b.match(/<div class="f10">(.+)<\/div><\/td>/);
					pubdate = mPubdate[1];	// 发布时间
					
					var  mComments = b.match(/<\/td>	<td class="tal f10 y-style">(\d+)<\/td>	<td class="tal y-style">/);
					comment = mComments[1];	// 评论数
				}
				
				listhtml += '<div class="item"  tapmode="itemActive" onclick="openTopic(' +tid+ ', \'' +title+ '\', \'' +author+ '\', \'' +pubdate+ '\')">'+
							'<div class="title">' +title+ '</div>'+
							'<div class="info">'+
							'<span class="author">' +author+ '</span><span class="time">' +pubdate+ '</span><span class="commentCount">' +comment+ '评论</span>'+
							'</div>'+
							'</div>';

			});
			$api.html($api.byId('list'), listhtml);
			
			// 返回到顶部
			if(type == 'prev' || type == 'next' || type == 'refresh'){
				$('body').scrollTop(0);
			}
			
	        if(type == 'refresh'){
	        	api.refreshHeaderLoadDone();
	        }
	        
	        $api.setStorage('nowPage', page);
	        
			api.execScript({	// 显示当前页码
			    name: 'win_forum_list',
			    script: 'setPage("'+page+'/'+$api.getStorage('totalPages')+'");'
			});
		
	    }else {
	        //log('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode);
	        showErrMgs(err.code, err.msg);

	    };
	api.parseTapmode();
	api.hideProgress();
	});
}


function openTopic(tid, title, author, pubdate){
    api.openWin({
        name: 'win_topic',
        url: 'win_topic.html',
        pageParam: {tid: tid, title: title, author: author, pubdate: pubdate}
    });
}
</script>
</body>
</html>